package com.example.remoteservic;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class MyremoteService extends Service  {
    // 实例化AIDL的Stub类(Binder的子类)并重写接口中的方法
   IMyAidlInterface.Stub mBinder = new IMyAidlInterface.Stub() {
        @Override
        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

        }

        @Override
        public void say() throws RemoteException {

            Toast.makeText(MyremoteService.this,"我是远程服务",Toast.LENGTH_LONG).show();

        }


    };
    public MyremoteService() {
    }

    //重写与Service生命周期的相关方法
    /*@Override
    public void onCreate() {
        super.onCreate();

        System.out.println("执行了onCreat()");

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        System.out.println("执行了onStartCommand()");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        System.out.println("执行了onDestory()");
    }*/

    @Nullable
    @Override
    //在onBind()返回继承自Binder的Stub类型的Binder，自定义服务内容非常重要(这里自定义的方法就是返回一个自定义的Binder)
    public IBinder onBind(Intent intent) {

        System.out.println("执行了onBind()");

        return mBinder;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        System.out.println("执行了onUnbind()");
        return super.onUnbind(intent);
    }




}

